package cn.tedu.util;

import java.util.ArrayList;
import java.util.LinkedList;

//测试 ArrayList和LinkedList的查询效率
public class Test2_2 {
    public static void main(String[] args) {
        method();
        method2();
    }

    public static void method2() {
        ArrayList<Integer> list=new ArrayList<>();
        for (int i = 0; i < 1000000; i++) {
            list.add(i);
        }
        long start= System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
        Integer date=list.get(i);
        }
        long end =System.currentTimeMillis();
        System.out.println(end-start);
    }

    public static void method() {
        LinkedList<Integer> list =new LinkedList<>();
        for (int i = 0; i < 100000; i++) {
            list.add(i);
        }
        long start=System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            Integer date =list.get(i);
        }
        long end =System.currentTimeMillis();
        System.out.println(end-start);
    }
}
